package com.zhiyuancode.mqack.message.base;

import org.apache.activemq.command.ActiveMQDestination;
import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.command.ActiveMQTopic;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * @author 杨志远
 * email faryangsh@163.com
 * Date    2018-06-05
 */
public enum MqTypeEnum {
    QUEUE("queue"), TOPIC("topic");

    private String type;

    private final static Map<String, MqTypeEnum> mqTypeMap = new HashMap<>();

    static {
        Arrays.stream(MqTypeEnum.values()).forEach(e -> {
            mqTypeMap.put(e.name(), e);
        });
    }

    MqTypeEnum(String type) {
        this.type = type;
    }

    private static MqTypeEnum acquireMqTypeEnum(String enumName) {
        return mqTypeMap.get(enumName);
    }

    public static ActiveMQDestination generateMqDestination(String address, String mqType) {
        MqTypeEnum mqTypeEnum = acquireMqTypeEnum(mqType);
        if (mqTypeEnum == TOPIC) {
            return new ActiveMQTopic(address);
        }
        return new ActiveMQQueue(address);

    }


}
